<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/16
 * Time: 15:27
 */
namespace app\common\logic;

class Config extends Base {

    private $financial_software_model;
    private $project_group_model;
    private $system_model;

    public function __construct()
    {
        parent::__construct();
        $this->financial_software_model = model("FinancialSoftware");
        $this->project_group_model = model("ProjectGroup");
        $this->system_model = model("System");
    }


    /**
     * 获取财务软件列表
     * @param array $where
     * @return mixed
     */
    public function getFinancialSoftwareList($where = [])
    {
        $list = $this->financial_software_model->getList($where, 100, false, true, true);

        return $list['data'];
    }

    /**
     * 获取项目组分类
     * @param array $where
     * @return mixed
     */
    public function getProjectGroupList($where = [])
    {
        $list = $this->project_group_model->getList($where, 100, false, true, true);
        /*按项目组id进行整理*/
        $res = [];
        foreach ($list['data'] as $v) {
            $res[$v['id']] = $v['group_name'];
        }

        return $res;
    }

    /**
     * 获取项目组分类，以项目组名称为key，id为value
     * @param array $where
     * @return mixed
     */
    public function getProjectGroupListReversal($where = [])
    {
        $list = $this->project_group_model->getList($where, 100, false, true, true);
        /*按项目组id进行整理*/
        $res = [];
        foreach ($list['data'] as $v) {
            $res[$v['group_name']] = $v['id'];
        }

        return $res;
    }

    /**
     * 获取其他配置项
     * @return array
     */
    public function getOtherSetList()
    {
        $set_list = $this->system_model->getList([], 50, false, true, true);

        return $set_list['data'];
    }

    /**
     * 保存配置
     * @param $name
     * @param $value
     * @return bool
     */
    public function saveOtherConfig($name, $value)
    {
        $res = $this->system_model->saveDate($name, [
            'value' => $value
        ]);

        if ($res === false) {
            return false;
        }
        return true;
    }

    /**
     * 获取其他配置项
     * @param $name
     * @return array
     */
    public function getOtherSetByName($name)
    {
        $set_info = $this->system_model->getInfo([
            'name' => $name,
        ]);

        return !empty($set_info['value']) ? $set_info['value'] : '';
    }
}